{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "from enum import Enum\n",
    "class Condition(Enum):\n",
    "    A = 1\n",
    "    B = 2\n",
    "    C = 3\n",
    "    D = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "go to ste one\n"
     ]
    }
   ],
   "source": [
    "values = [1, 2, 3, 4]\n",
    "choice = Condition(random.choice(values))\n",
    "#if choice == Condition.A or choice == Condition.B or choice == Condition.C:\n",
    "#    print('go to step one')\n",
    "#else:\n",
    "#    print('go to step two')\n",
    "\n",
    "if choice == Condition.D:\n",
    "    print('go to step two')\n",
    "else:\n",
    "    print('go to ste one')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "go to step two\n"
     ]
    }
   ],
   "source": [
    "values = [1, 2, 3, 4]\n",
    "choice = Condition(random.choice(values))\n",
    "if choice == Condition.A or choice == Condition.B:\n",
    "    print('go to step one')\n",
    "else:\n",
    "    print('go to step two')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "go to step two\n"
     ]
    }
   ],
   "source": [
    "values = [1, 2, 3, 4]\n",
    "choice = Condition(random.choice(values))\n",
    "options = [Condition.A, Condition.B]\n",
    "if choice in options:\n",
    "    print('go to step one')\n",
    "else:\n",
    "    print('go to step two')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "go to step one\n"
     ]
    }
   ],
   "source": [
    "values = [1, 2, 3, 4]\n",
    "choice = Condition(random.choice(values))\n",
    "options = {Condition.A, Condition.B}\n",
    "if choice in options:\n",
    "    print('go to step one')\n",
    "else:\n",
    "    print('go to step two')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.421018123626709\n"
     ]
    }
   ],
   "source": [
    "# 直接判断\n",
    "import time\n",
    "choice = Condition.C\n",
    "start_time = time.time()\n",
    "for i in range(0, 1000000):\n",
    "    if choice == Condition.A or choice == Condition.B or choice == Condition.C:\n",
    "        pass\n",
    "    else:\n",
    "        pass\n",
    "end_time = time.time()\n",
    "print(end_time - start_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.09975171089172363\n"
     ]
    }
   ],
   "source": [
    "# 放到List里\n",
    "import time\n",
    "choice = Condition.C\n",
    "start_time = time.time()\n",
    "options = [Condition.A, Condition.B, Condition.C]\n",
    "for i in range(0, 1000000):\n",
    "    if choice in options:\n",
    "        pass\n",
    "    else:\n",
    "        pass\n",
    "end_time = time.time()\n",
    "print(end_time - start_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.21266388893127441\n"
     ]
    }
   ],
   "source": [
    "# 放到SET里\n",
    "import time\n",
    "choice = Condition.C\n",
    "start_time = time.time()\n",
    "options = {Condition.A, Condition.B, Condition.C}\n",
    "for i in range(0, 1000000):\n",
    "    if choice in options:\n",
    "        pass\n",
    "    else:\n",
    "        pass\n",
    "end_time = time.time()\n",
    "print(end_time - start_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
